﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HousingPic.aspx.cs" Inherits="ZLDC.Estate.PM.HousingPic" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>从图片库里选择户型图</title>
    <base target="_self" />
    <link href="../css/main.css" rel="stylesheet" type="text/css" />

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <script src="../js/jquery/jquery.hiAlerts-min.js" type="text/javascript"></script>
    <script type="text/javascript">


        $(document).ready(function() {
            var id = LexunJS.GetQueryString("id");  // 楼盘ID
            // 修改
            if (id > 0) {
                showHousingPic('div1');
            }
        });
        
        //上传图片
        function ShowDialogPic(typeid, typename) {
            var id = LexunJS.GetQueryString("id");
            var path = "../swfupload/index.aspx?url=" + encodeURI("~/TM/savephoto.aspx&type=" + typeid + "&id=" + id + "&typename=" + typename);
            var parameter = "";
            var style = "dialogWidth:538px; dialogHeight:563px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
            window.showModalDialog(path, parameter, style);
            location.reload();
        }
        
        // 房屋照片
        function showHousingPic(divId) {
            var id = LexunJS.GetQueryString("id");

            $("#" + divId).html("<img src=\"../images/loading.gif\" />"); // 清空列表 
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerHousing.ashx',
                data: 'act=estatepic_list&eid=' + id + '&type=2',
                timeout: '10000',
                error: function() {
                    alert("查询失败！");
                },
                success: function(json) {
                    showHousingPicCallBack(json, divId);
                }
            });
        }

        function showHousingPicCallBack(response, divId) {
            var json = eval("(" + response + ")");
            var record = json.record;
            if (record == null || record.length == 0) {
                $("#" + divId).html(""); // 清空列表
                hiOverAlert("系统内暂无该楼盘的图片信息,请给楼盘上传图片！", 2000);
                return;
            }
            var arr = [];
            if (divId == "div1") {
                arr.push("<img alt='' onclick='SavePic();' src='../images/bot2.gif' width='85px' height='33px'/>");
            }
            arr.push("<ul class='youxi_left_ul'>");
            var recordLength = record.length;

            for (var i = 0; i < recordLength; i++) {
                if (i % 6 == 0 && i > 0)
                    arr.push("</ul><ul class='youxi_left_ul'>");
                arr.push("<li>");

                arr.push("<img id='img" + record[i].id + "' title='户型图' style='width:120px;height:100px;' src='../" + record[i].picurl + "' /><br/><input id='hpic' name='hpic' value='" + record[i].picurl + "' type='radio' />");
                arr.push("<br/>" + record[i].remark + "   <br/>上传人:" + record[i].user + "[" + record[i].dept + "]<br/>上传时间:" + record[i].createtime)

                arr.push("</li>");
            }
            arr.push("</ul>");
            $("#" + divId).html(arr.join('')); // 显示列表
        }

        function SavePic() {
            var arrInputControls;
            arrInputControls = document.getElementsByName("hpic");
            var hAppliances = "";
            for (i = 0; i < arrInputControls.length; i++) {
                if (arrInputControls(i).checked == true) {
                    hAppliances += arrInputControls(i).value + ",";
                }
            }
            if (hAppliances != "") {
                hAppliances = hAppliances.substr(0, hAppliances.length - 1);
            }
            if (hAppliances == "") {
                alert("请选择图片");
                return;
            }
            var id = LexunJS.GetQueryString("id");
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerHousing.ashx',
                data: 'act=p_HosingPic_insert&id=' + id + '&picurl=' + hAppliances,
                timeout: '10000',
                error: function() {
                    alert("保存失败！");
                },
                success: function(json) {
                    if (json == "添加成功") {
                        window.close();
                    } else {
                        alert(json);
                    }

                }
            });
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="div1" class="page f_l">
    </div>
    </form>
</body>
</html>
